#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


# Exercise 1.3.27 - Write a program Checkerboard that takes one
command-line argument and uses a loop within a loop to print a two-dimensional
pattern with alternating spaces and asterisks.

Syntax:
python checkerboard.py 9


Notes:
int(sys.argv[1]) == Integer.parseInt(args[0])

sys is a required import here in order to use command line arguments.
https://docs.python.org/2/tutorial/stdlib.html

'''

import sys


def main():
    ''' Print a checkerboard of alternating spaces/asterisks '''

    n_by_n = int(sys.argv[1])
    for row in range(n_by_n):
        for col in range(n_by_n):
            if row % 2 == 0:
                if col % 2 == 0:
                    sys.stdout.write("*")
                else:
                    sys.stdout.write(" ")
            else:
                if col % 2 == 0:
                    sys.stdout.write(" ")
                else:
                    sys.stdout.write("*")
        print


if __name__ == '__main__':
    main()
